package com.migu.spms.webapi;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.migu.spms.service.data.User;
import com.migu.spms.service.inf.IFunctionFlowService;
import com.migu.spms.webapi.data.FunctionFlowRequest;

@Controller
@RequestMapping(value = "/flow", produces = "application/json;charset=UTF-8")
public class FunctionFlowController extends BaseController {
	@Resource(name="functionFlowServiceImpl")
	private IFunctionFlowService functionFlowService;
    
	@ResponseBody  
    @RequestMapping(value = "/operateFlow")
	public String operateFlow(HttpServletRequest req, HttpServletResponse resp,String sessionId)throws Exception{
		User user = getUserBySession(req, sessionId);
        if (user == null) {
           return generateResponse(401);
         }
		FunctionFlowRequest flowRequest=ParseMsg(req, FunctionFlowRequest.class);
        	functionFlowService.operateFlow(flowRequest, user);
        	return generateResponse(200);
//        
	}
	
	@ResponseBody  
    @RequestMapping(value = "/startProcessFlow")
	public String startProcessFlow(HttpServletRequest req, HttpServletResponse resp,String sessionId)throws Exception{
		User user = getUserBySession(req, sessionId);
//      if (user == null) {
//          return generateResponse(401);
//       }else{
//		User user=new User();
//		user.setUserId(1);
//		user.setUserName("李乐1");
		FunctionFlowRequest flowRequest=ParseMsg(req, FunctionFlowRequest.class);
        functionFlowService.startProcessFlow(flowRequest.getPrimaryKey(), user);
        return generateResponse(200);
	}
	
	
	
}
